<?php
/**
 * @author Administrator
 *
 */
class SmsSender {

	/**
	 */
	function __construct() {
	}
	/**
	 * 发送短信验证码 阿里云短信
	 * @param string $phone
	 * @param string $code
	 */
	public function captcha($phone,$code){
        try {
            $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
            $sendurl = $http_type.$_SERVER['HTTP_HOST'].'/alisms/index.php?phone='.$phone.'&code='.$code;
            $result =file_get_contents($sendurl);
            $response = json_decode($result,true);
            if($response['code'] == 200){
                return true;
            }else{
                return false;
            }
        }catch (\Exception $e){
           return $e->getMessage();
        }
	}

	/**
	 * 发送短信验证码 健康宝短信
	 * @param string $phone
	 * @param string $code
	 */
	public function captcha_bao($phone,$code){
		$statusStr = array(
			"0" => "短信发送成功",
			"-1" => "参数不全",
			"-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
			"30" => "密码错误",
			"40" => "账号不存在",
			"41" => "余额不足",
			"42" => "帐户已过期",
			"43" => "IP地址限制",
			"50" => "内容含有敏感词"
		);
		$smsapi = "http://api.smsbao.com/";
		$user = "runjoy888"; //短信平台帐号
		$pass = "10e6268eeec1432ab1cf64ac7ede1f5e"; //短信平台密码
		$time = "十";
		$sign_name = '荣钧健康饮水';
		$content="【{$sign_name}】您的验证码是:{$code}，{$time}分钟内有效。如非本人操作，请忽略本条短信。";//要发送的短信内容
		$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
		try{
			$result =file_get_contents($sendurl);
			$status_txt = $statusStr[$result];
			if($result == 0){
				return true;
			}else{
				return false;
			}
		}catch(\Exception $e){
			return false;
		}
	}
}

